#include "Tree.h"

//考虑到后序遍历的倒数第二个节点刚好为右节点

class Solution {
public:
    int preIndex = 0, posIndex = 0;
    TreeNode* constructFromPrePost(vector<int>& preorder, vector<int>& postorder) {
        TreeNode* root = new TreeNode(preorder[preIndex++]);
        if (root->val != postorder[posIndex]) 
            root->left = constructFromPrePost(preorder, postorder);
        if (root->val != postorder[posIndex]) 
            root->right = constructFromPrePost(preorder, postorder);
        posIndex++;
        return root;

    }
};